package com.pysrc.base.service.impl;

import com.github.pagehelper.PageHelper;
import com.pysrc.base.mapper.BaseMapper;
import com.pysrc.base.service.BaseService;

import java.util.List;

/**
 * @ClassName:
 * @Auther L.Chen
 * @CreateDate
 * @Description TODO
 */
public abstract class BaseServiceImpl<T> implements BaseService<T> {
    protected BaseMapper<T> mapper;
    @Override
    public T insert(T t) {
        return mapper.insert(t)==0? null :t;
    }

    @Override
    public T updateByPrimaryKey(T t) {
        return mapper.updateByPrimaryKey(t)==0?null:t;
    }

    @Override
    public T deleteByPrimaryKey(Long id) {
        T t = mapper.selectByPrimaryKey(id);
        return mapper.deleteByPrimaryKey(id)==0?null:t;
    }

    @Override
    public T selectByPrimaryKey(Long id) {
        return mapper.selectByPrimaryKey(id);
    }

    @Override
    public List<T> select(T t) {
        return mapper.select(t);
    }

    @Override
    public List<T> select(T t, Integer page, Integer pageSize) {
        if(page!=null&&pageSize!=null){
            PageHelper.startPage(page,pageSize);
        }
        return mapper.select(t);
    }
}
